package com.cloudpivot.receivales.contract.configuration;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateSettings;
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;
import java.util.Map;


@Configuration
public class DataSourceConfig {
    /**
     * 第一个数据源
     */
    @Primary
    @Bean(name = "dataSourceOne")
    @ConfigurationProperties(prefix = "spring.datasource.one")
    public DataSource dataSourceOne(){
        return DataSourceBuilder.create().build();
    }

    /**
     * 第二个数据源
     */
    @Bean(name="dataSourceTwo")
    @ConfigurationProperties(prefix = "spring.datasource.two")
    public DataSource dataSourceTwo(){
        return DataSourceBuilder.create().build();
    }

    /**
     * 第三个数据源 bi
     * @return
     */
    @Bean(name="dataSourceThree")
    @ConfigurationProperties(prefix = "spring.datasource.three")
    public DataSource dataSourceThree(){
        return DataSourceBuilder.create().build();

    }

    /**
     * 第四个数据源
     */
    @Bean(name="dataSourceFour")
    @ConfigurationProperties(prefix = "spring.datasource.four")
    public DataSource dataSourceFour(){
        return DataSourceBuilder.create().build();

    }

    /**
     * 第五个数据源
     */
    @Bean(name="dataSourceFive")
    @ConfigurationProperties(prefix = "spring.datasource.five")
    public DataSource dataSourceFive(){
        return DataSourceBuilder.create().build();

    }

    @Autowired
    private JpaProperties jpaProperties;
    @Autowired
    private HibernateProperties hibernateProperties;

    @Bean(name = "vendorProperties")
    public Map<String, Object> getVendorProperties() {
        return hibernateProperties.determineHibernateProperties(jpaProperties.getProperties(), new HibernateSettings());
    }

}
